//id ,是否折叠其他,默认显示第几个 0开始
var water1, water2;
sui.ready(function() {

	water1 = document.querySelector('#water1');
	water2 = document.querySelector('#water2');
	//console.info(water1);
	//setDate();
	//setSvg();
	//beginAnimation();



})

var vm = new Vue({
	el: "#datas",
	data: {
		switchStatus: [0, 0, 0, 0, 0, 0],

		selectIndex: -1,
		selectStatus: -1,
	},
	mounted: function() {

	},
	methods: {
		radioClass: function(index) {
			return this.switchStatus[index] == 1 ? "radio-on" : "radio-off"
		},

		onRadioClicked: function(index) {
			if (this.selectIndex >= 0) {
				sui.toast("请等待开关动作完成");
				return;
			}

			var status = this.switchStatus[index] == 0 ? 1 : 0;
			this.selectIndex = index;
			this.selectStatus = status;
			controlTarget(index, status);
		},

		bengClass: function(index) {
			var status = this.switchStatus[index] || false;
			return status == true ? "img/beng_2.png" : "img/beng_1.png"
		}
	},
})

var timeControll = null; //定时器
// 控制开门，开关风机等操作(0:关 | 1：开) / (0：开门 | 1：风机 | 2：开阀1 | 3：开阀2 | 4：开排污阀)
function controlTarget(type, action) {
	sui.loading("控制中...");
	console.log("发起请求:" + type + "|" + action);
	try {
		jsObjAsync.controlTarget(type, action);
	} catch (e) {
		sui.toast("发送控制失败");
		// setTimeout(function() {
		// 	refreshControl(1);
		// }, 7000)
	}

	timeControll = setTimeout(function() {
		console.log("计时器时间到")
		if (vm.selectIndex >= 0) {
			refreshControl(99);
		}
	}, 5000)
}

// 后台刷新前台控制状态（后台调用前台方法）
function refreshControl(state) {
	console.log("请求返回:" + vm.selectIndex + "|" + state);
	sui.closeLoading();
	window.clearTimeout(timeControll);
	if (state == 0) {
		//下发成功
		vm.$set(vm.switchStatus, vm.selectIndex, vm.selectStatus);
		vm.selectIndex = -1;
	} else if (state == 99) {
		//下发超时
		sui.toast("控制超时");
		vm.selectIndex = -1;
	} else {
		//下发失败
		sui.toast("控制返回失败");
		vm.selectIndex = -1;
	}
}



